package com.js.purs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.js.purs.mapper.PurOpenBindMapper;
import com.js.purs.domain.PurOpenBind;
import com.js.purs.service.IPurOpenBindService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目开标Service业务层处理
 *
 * @author ruoyi
 * @date 20240704
 */
@Service
public class PurOpenBindServiceImpl implements IPurOpenBindService {
    @Autowired
    private PurOpenBindMapper purOpenBindMapper;

    /**
     * 查询项目开标
     *
     * @param bindCode 项目开标主键
     * @return 项目开标
     */
    @Override
    public PurOpenBind selectPurOpenBindByOpenCode(String bindCode) {
        return purOpenBindMapper.selectPurOpenBindByOpenCode(bindCode);
    }

    /**
     * 查询项目开标列表
     *
     * @param purOpenBind 项目开标
     * @return 项目开标
     */
    @Override
    public List<PurOpenBind> selectPurOpenBindList(PurOpenBind purOpenBind) {
        return purOpenBindMapper.selectPurOpenBindList(purOpenBind);
    }

    /**
     * 新增项目开标
     *
     * @param purOpenBind 项目开标
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertPurOpenBind(PurOpenBind purOpenBind) {
        PurOpenBind bind = purOpenBindMapper.selectPurOpenBindByOpenCode(purOpenBind.getBindCode());
        if (bind != null && bind.getBindCode() != null) {
            //删除
            System.out.println("删除再新增");
            purOpenBindMapper.deletePurOpenBindByOpenCode(purOpenBind.getBindCode());
            //新增
            purOpenBind.setCreateTime(DateUtils.getNowDate());
            return purOpenBindMapper.insertPurOpenBind(purOpenBind);
        }
        System.out.println("新增");
        return purOpenBindMapper.insertPurOpenBind(purOpenBind);

    }

    /**
     * 修改项目开标
     *
     * @param purOpenBind 项目开标
     * @return 结果
     */
    @Override
    public int updatePurOpenBind(PurOpenBind purOpenBind) {
        return purOpenBindMapper.updatePurOpenBind(purOpenBind);
    }

    /**
     * 批量删除项目开标
     *
     * @param openCodes 需要删除的项目开标主键
     * @return 结果
     */
    @Override
    public int deletePurOpenBindByOpenCodes(String[] openCodes) {
        return purOpenBindMapper.deletePurOpenBindByOpenCodes(openCodes);
    }

    /**
     * 删除项目开标信息
     *
     * @param bindCode 项目开标主键
     * @return 结果
     */
    @Override
    public int deletePurOpenBindByOpenCode(String bindCode) {
        return purOpenBindMapper.deletePurOpenBindByOpenCode(bindCode);
    }
}
